<!-- $Id: rg_coupons_info.htm 14361 2008-04-07 09:26:17Z zhuwenyuan $ -->
{include file="pageheader.htm"}
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
{insert_scripts files="validator.js,../js/transport.org.js}
<div class="main-div">
<form method="post" action="rg_coupons.php" name="theForm" enctype="multipart/form-data" onSubmit="return validate()">
<table cellspacing="1" cellpadding="3" width="100%">
  <tr>
    <td class="label">优惠券名称</td>
    <td><input name="cou_name" type="text" id="cou_name" value="{$coupons.cou_name}" size="40" /></td>
  </tr>
  <tr>
    <td class="label">开始时间</td>
    <td><input name="start_time" type="text" id="start_time" value="{$coupons.start_time}" readonly />
        <input name="selbtn1" type="button" id="selbtn1" onclick="return showCalendar('start_time', '%Y-%m-%d %H:%M', '24', false, 'selbtn1');" value="{$lang.btn_select}" class="button" /></td>
  </tr>
  <tr>
    <td class="label">结束时间</td>
    <td><input name="end_time" type="text" id="end_time" value="{$coupons.end_time}" readonly />
        <input name="selbtn2" type="button" id="selbtn2" onclick="return showCalendar('end_time', '%Y-%m-%d %H:%M', '24', false, 'selbtn2');" value="{$lang.btn_select}" class="button" /></td>
  </tr>
  <tr>
    <td class="label">享受会员等级</td>
    <td>{foreach from=$user_rank_list item=user_rank}<label><input type="checkbox" name="user_rank[]" value="{$user_rank.rank_id}" {if $user_rank.checked}checked="true"{/if} />{$user_rank.rank_name}</label> {/foreach}</td>
  </tr>
  <tr>
    <td class="label">优惠范围</td>
    <td><select name="cou_range" onchange="changeRange(this.value)">
          <option value="1" {if $coupons.cou_range eq 1}selected="selected"{/if}>以下分类</option>
          <option value="2" {if $coupons.cou_range eq 2}selected="selected"{/if}>以下品牌</option>
          <option value="3" {if $coupons.cou_range eq 3}selected="selected"{/if}>以下商品</option>
        </select>
      <div id="range-div">{foreach from=$cou_range_ext item=item}<input name="cou_range_ext[]" type="checkbox" value="{$item.id}" checked="checked" />{$item.name} {/foreach}</div></td>
  </tr>
  <tr id="range_search">
    <td align="right">搜索并加入优惠范围</td>
    <td><input name="keyword" type="text" id="keyword">
      <input name="search" type="button" id="search" value="{$lang.button_search}" class="button" onclick="searchItem()" />
      <select name="result" id="result">
      </select> <input type="button" name="add_range" value="+" class="button" onclick="addRange()" />
      </a></td>
  </tr>

{if $form_action == 'insert'}
  <tr>
    <td class="label">优惠码</td>
    <td><input type="text" name="code_name" value="{$coupons.code_name}" /></td>
  </tr>
  <tr>
    <td class="label"><a href="javascript:showNotice('NoticeActType');" title="{$lang.form_notice}"><img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}"></a>优惠方式</td>
    <td><select name="code_type" id="code_type">
      <option value="1" {if $coupons.code_type eq 1}selected="selected"{/if}>享受现金减免</option>
      <option value="2" {if $coupons.code_type eq 2}selected="selected"{/if}>享受价格折扣</option>
      </select>
      <input name="code_fee" type="text" id="code_fee" size="10" />
      <br />
      <span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="NoticeActType">当优惠方式为“享受现金减免”时，请输入现金减免的金额；当优惠方式为“享受价格折扣”时，请输入折扣（1－99），如：打9折，就输入90。</span>
	</td>
  </tr>
{else}
  <tr>
    <td class="label">优惠码</td>
    <td>{$coupons.code_name} ~ {if $coupons.code_type eq 1}现金减免{elseif $coupons.code_type eq 2}价格折扣{/if}<font color="red">{$coupons.code_fee}</font></td>
  </tr>
{/if} 
      <tr>
        <td class="narrow-label">上传文件</td>
        <td><input type="file" name="file">
          <span class="narrow-label">{$lang.file_url}
          <input name="file_url" type="text" value="{$coupons.cou_img|escape}" size="30" maxlength="255" />
          </span></td>
      </tr>
  <tr>
    <td colspan="2" align="center">
      <input type="submit" class="button" value="{$lang.button_submit}" />
      <input type="reset" class="button" value="{$lang.button_reset}" />
      <input type="hidden" name="act" value="{$form_action}" />
      <input type="hidden" name="id" value="{$coupons.cou_id}" /></td>
  </tr>
</table>
</form>
</div>

{literal}
<script language="JavaScript">
onload = function(){
    startCheckOrder();
}

function validate()
{
    validator = new Validator("theForm");
    validator.required('cou_name', '请输入优惠活动名称');
    validator.isNumber('code_fee', '优惠方式后面的值不正确（数字）', 1);
    validator.islt('start_time', 'end_time', '优惠开始时间不能大于结束时间');
	
	{if $form_action == 'insert'}
    validator.required("code_name",   '优惠码为空，请输入', 1);
	{/if}
	
    return validator.passed();
}

function searchItem()
{
  var filter = new Object;
  filter.keyword  = document.forms['theForm'].elements['keyword'].value;
  filter.cou_range = document.forms['theForm'].elements['cou_range'].value;
  Ajax.call('rg_coupons.php?is_ajax=1&act=search', filter, searchResponse, 'GET', 'JSON');
}

function searchResponse(result)
{
  if (result.error == '1' && result.message != '')
  {
    alert(result.message);
	return;
  }

  var sel = document.forms['theForm'].elements['result'];

  sel.length = 0;

  /* 创建 options */
  var goods = result.content;
  if (goods)
  {
    for (i = 0; i < goods.length; i++)
    {
      var opt = document.createElement("OPTION");
      opt.value = goods[i].id;
      opt.text  = goods[i].name;
      sel.options.add(opt);
    }
  }

  return;
}

/**
 * 改变优惠范围
 * @param int rangeId
 */
function changeRange(rangeId)
{
  document.getElementById('range-div').innerHTML = '';
  document.getElementById('result').length = 0;
  var row = document.getElementById('range_search');
  if (rangeId <= 0)
  {
    row.style.display = 'none';
  }
  else
  {
    row.style.display = '';
  }
}

function addRange()
{
  var selRange = document.forms['theForm'].elements['cou_range'];
  
  var selResult = document.getElementById('result');
  if (selResult.value == 0){
    alert('请先搜索');
    return;
  }
  var id = selResult.options[selResult.selectedIndex].value;
  var name = selResult.options[selResult.selectedIndex].text;

  // 检查是否已经存在
  var exists = false;
  var eles = document.forms['theForm'].elements;
  for (var i = 0; i < eles.length; i++)
  {
    if (eles[i].type=="checkbox" && eles[i].name.substr(0, 13) == 'cou_range_ext')
    {
      if (eles[i].value == id){
        exists = true;
        alert('该选项已存在');
        break;
      }
    }
  }

  // 创建checkbox
  if (!exists){
    var html = '<input name="cou_range_ext[]" type="checkbox" value="' + id + '" checked="checked" />' + name + '<br />';
    document.getElementById('range-div').innerHTML += html;
  }
}
</script>
{/literal}
{include file="pagefooter.htm"}
